<?php
// +----------------------------------------------------------------------
// | 角色模块
// +----------------------------------------------------------------------
// | Author: 李乾坤 <261001642@qq.com>
// +----------------------------------------------------------------------
class AuthGroupAction extends CommonAction {
    public function _filter($map){
        if($_REQUEST['title']!=""){
            $map['title']=array('like',"%".$_REQUEST['title']."%");
        }
        return $map;
    }
    /*function authorize(){
        $role_id=$_GET['role_id'];
        $AuthGroup=M('AuthGroup');
        $AuthRule=M('AuthRule');
        $Group=M('Group');
        $AuthList=$Group->where('status=1')->select();
        foreach ($AuthList as $key => $value) {
            $AuthList[$key]['rules']=$AuthRule->where('group_id='.$value['id'])->select();
        }
        $otherlist=$AuthRule->where('group_id=0')->select();
        if (!empty($otherlist)){
            $AuthList[]=array(
                'title'=>'其他',
                'rules'  =>$otherlist
            );
        }
        $this->assign('AuthList',$AuthList);
        $this->assign('Role',$AuthGroup->find($role_id));
        $this->display();
    }*/
    function _before_edit(){
        //$role_id=intval($_GET['role_id']);
        $AuthGroup=M('AuthGroup');
        $AuthRule=M('AuthRule');
        $Group=M('Group');
        $AuthList=$Group->where('status=1')->select();
        foreach ($AuthList as $key => $value) {
            $AuthList[$key]['rules']=$AuthRule->where('group_id='.$value['id'])->select();
        }
        $otherlist=$AuthRule->where('group_id=0')->select();
        if (!empty($otherlist)){
            $AuthList[]=array(
                'title'=>'其他',
                'rules'  =>$otherlist
            );
        }
        $this->assign('AuthList',$AuthList);
        //$this->assign('Role',$AuthGroup->find($role_id));
    }
    function _before_add(){
        $this->_before_edit();
    }
    function _before_update(){
        $this->_before_insert();
    }
    function _before_insert(){
        $_POST['rules']=implode(',',$_POST['rules']);
    }
    function cache(){
        $this->getMenu(null,true);
        $this->success('缓存生成成功!');
    }
    /*function saveauthorize(){
        $rules=implode(',',$_POST['rules']);
        $AuthGroup=M('AuthGroup');

    }*/
}
?>